import datetime
import time
from datetime import timedelta

now = datetime.datetime.now(tz=None)
ts = time.time()

# datetime.datetime对象转换为时间戳
now_ts = now.timestamp()
print("datetime.datetime对象转换为时间戳: now_ts =", now_ts)

# 时间戳转换为datetime.datetime对象
ts_now = datetime.datetime.fromtimestamp(ts, tz=None)
print("时间戳转换为datetime.datetime对象: ts_now =", ts_now)
print("ts_now数据类型:", type(ts_now))

print('\n')

# datetime.datetime对象转换为字符串
now_s = now.strftime("%Y-%m-%d %H:%M:%S")
print("datetime.datetime对象转换为字符串: now_s =", now_s)

# 字符串转换为datetime.datetime对象
s_now = datetime.datetime.strptime(now_s, "%Y-%m-%d %H:%M:%S")
print("字符串转换为datetime.datetime对象: s_now =", s_now)
print("s_now数据类型: ", type(s_now))

print('\n')

# 时间戳转换为字符串
t_n = datetime.datetime.fromtimestamp(ts, tz=None)
n_s = t_n.strftime("%Y-%m-%d %H:%M:%S")
print("时间戳转换为字符串: n_s =", n_s)

# 字符串转换为时间戳
s_n = datetime.datetime.strptime(n_s, "%Y-%m-%d %H:%M:%S")
n_t = s_n.timestamp()
print("字符串转换为时间戳: n_t =", n_t)

print('\n')


def get_date(day_delt):
    n = datetime.datetime.now(tz=None)
    n = n + timedelta(days=day_delt)
    s = n.strftime("%Y-%m-%d")
    print("进行运算后时间: ", s)
    return None

x = int(input("请输入需要运算的天数:\n"))
get_date(x)